const path = require('path');
const templateDir = path.resolve(__dirname,'../template/');	//模板路径
var HtmlWebpackPlugin = require('html-webpack-plugin');
const inputPath = './src/app/';
var merge = require('webpack-merge');
const baseConfig = {	//基本配置
	minify: {
        removeComments: true,
        collapseWhitespace: true,
        removeAttributeQuotes: true
        // more options:
        // https://github.com/kangax/html-minifier#options-quick-reference
    },
    chunksSortMode: 'dependency',
    chunks:['basestyle','manifest','vendor'],
};
//产生需要发布的html-webpack-plugin的数组
function genPlguins(arr){
	var pubArr = [];
	arr.forEach(function(item){
		let obj = {
			filename:item.name+'.html',
			template: item.hasOwnProperty('template') ?item.template : templateDir+'/index.html',
			chunks:[item.name]
		};
		obj = merge(baseConfig,obj);
		pubArr.push(new HtmlWebpackPlugin(obj));
//		console.log(obj);
	});
	return pubArr;
};
//产生生产环境需要的input
function genInput(arr){
	var obj = {};
	arr.forEach((item)=>{
		obj[item.name] = inputPath + item.name + '/main.js'
	});
	return obj;
};

var pubModel = [
	{name:'index',},	//主页模块
	{name:'login'},	//登陆模块
];


exports.pluginsArr = genPlguins(pubModel);
exports.inputObj = genInput(pubModel);
